unit RelatorioOcorrenciaNotaFiscalResumo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UFormRelatorio, DB, DBTables, StdCtrls, QRCtrls, QuickRpt,
  ExtCtrls;

type
  TFRelatorioOcorrenciaVendaNotaFiscalResumo = class(TFormRelatorio)
    QRLabel4: TQRLabel;
    QRLabel5: TQRLabel;
    QRLabel6: TQRLabel;
    QRLabel7: TQRLabel;
    QRLabel8: TQRLabel;
    QRBand2: TQRBand;
    QRDBText2: TQRDBText;
    QRDBText3: TQRDBText;
    QRExpr1: TQRExpr;
    QRExpr2: TQRExpr;
    QRDBText24: TQRDBText;
    QRDBText1: TQRDBText;
    QRLabel33: TQRLabel;
    QRLabel38: TQRLabel;
    QRLabel39: TQRLabel;
    QRLabel66: TQRLabel;
    QRLabel68: TQRLabel;
    QRLabel64: TQRLabel;
    QRBand3: TQRBand;
    QRExpr4: TQRExpr;
    QRLabel29: TQRLabel;
    QRLabel35: TQRLabel;
    QRLabel10: TQRLabel;
    QRLabel11: TQRLabel;
    QRDBText4: TQRDBText;
    QRDBText5: TQRDBText;
    QRDBText6: TQRDBText;
    QRDBText7: TQRDBText;
    QRDBText8: TQRDBText;
    QRDBText9: TQRDBText;
    QRDBText10: TQRDBText;
    QRLabel9: TQRLabel;
    QRExpr3: TQRExpr;
    QRExpr7: TQRExpr;
    QRExpr8: TQRExpr;
    QRExpr9: TQRExpr;
    QRExpr10: TQRExpr;
    QRExpr11: TQRExpr;
    QRExpr12: TQRExpr;
    QRLRetido: TQRLabel;
    QRLNaoRetido: TQRLabel;
    QRExpr5: TQRExpr;
    QRLabel12: TQRLabel;
    QRShape1: TQRShape;
    procedure FormCreate(Sender: TObject);
    procedure QRBand2BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRBand3BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
    procedure QRLabel3Print(sender: TObject; var Value: String);
    procedure QRSysData3Print(sender: TObject; var Value: String);
    procedure QRDBText10Print(sender: TObject; var Value: String);
    procedure QRExpr12Print(sender: TObject; var Value: String);
  private
    { Private declarations }
  public
    { Public declarations }
   Retido,naoRetido :Real;
  end;

var
  FRelatorioOcorrenciaVendaNotaFiscalResumo: TFRelatorioOcorrenciaVendaNotaFiscalResumo;
  valorTotalLiquido : real = 0.0;
implementation

uses UGeral, PesquisaOcorrenciaNotaFiscalResumo;

{$R *.dfm}

procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.FormCreate(Sender: TObject);
begin
  inherited;
 Retido:=0;
 naoRetido:=0;
 QRLRetido.Caption:='';
 QRLNaoRetido.Caption:='';

 QRelatorio.Close;
 QRelatorio.SQL.Clear;
 QRelatorio.SQL.Add('Select Emp_Razao as Razao from empresa ');
 QRelatorio.SQL.Add('Where Emp_Codigo = :Cod ');
 QRelatorio.ParamByName('Cod').AsInteger:=Codigoempresa;
 QRelatorio.Open;
 QRLNomeEmpresa.Caption:=UpperCase(QRelatorio.fieldByname('Razao').AsString);

end;

procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.QRBand2BeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);
begin
  inherited;

 if FPesquisaOcorrenciaVendaNotaFiscalResumo.QPesquisa.FieldByName('NF_RETEMISS').AsInteger = 0 then
  naoRetido:=naoRetido + FPesquisaOcorrenciaVendaNotaFiscalResumo.QPesquisa.FieldByName('NF_VALORISS').AsFloat
 else
  if FPesquisaOcorrenciaVendaNotaFiscalResumo.QPesquisa.FieldByName('NF_RETEMISS').AsInteger = 1 then
   Retido:=Retido + FPesquisaOcorrenciaVendaNotaFiscalResumo.QPesquisa.FieldByName('NF_VALORISS').AsFloat;


end;

procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.QRBand3BeforePrint(
  Sender: TQRCustomBand; var PrintBand: Boolean);
begin
  inherited;
 QRLRetido.Caption:=FormatFloat('0.,00',Retido);
 QRLNaoRetido.Caption:=FormatFloat('0.,00',naoRetido);

 Retido:=0;
 naoRetido:=0;
end;


procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.QRLabel3Print(
  sender: TObject; var Value: String);
begin
  inherited;
  value:='';
end;

procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.QRSysData3Print(
  sender: TObject; var Value: String);
begin
  inherited;
value:='';
end;

procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.QRDBText10Print(
  sender: TObject; var Value: String);
var
  valor : real;
begin
  inherited;
  valor := 0.0;
 if FPesquisaOcorrenciaVendaNotaFiscalResumo.cbLiquido.Checked then
 begin
   valor := QRDBText10.DataSet.FieldByName('NF_VALORISS').AsFloat +
            QRDBText10.DataSet.FieldByName('NF_VALORCOFINS').AsFloat +
            QRDBText10.DataSet.FieldByName('NF_VALORPIS').AsFloat +
            QRDBText10.DataSet.FieldByName('NF_VALORCSLL').AsFloat +
            QRDBText10.DataSet.FieldByName('NF_VALORIRRF').AsFloat +
            QRDBText10.DataSet.FieldByName('NF_VALORINSS').AsFloat;

   value := FormatFloat('#,##0.00',(QRDBText10.DataSet.FieldByName('NF_VALORFINALNOTA').AsFloat - valor));
   valorTotalLiquido := valorTotalLiquido +
   (QRDBText10.DataSet.FieldByName('NF_VALORFINALNOTA').AsFloat - valor);
 end;
end;

procedure TFRelatorioOcorrenciaVendaNotaFiscalResumo.QRExpr12Print(
  sender: TObject; var Value: String);
begin
  inherited;
  if FPesquisaOcorrenciaVendaNotaFiscalResumo.cbLiquido.Checked then
    value := FormatFloat('#,##0.00',valorTotalLiquido);
  valorTotalLiquido := 0.0;
end;

end.
